package com.changgou.user.controller;
import com.changgou.user.pojo.OauthApprovals;
import com.changgou.user.service.OauthApprovalsService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/oauthApprovals")
@CrossOrigin
public class OauthApprovalsController {

    @Autowired
    private OauthApprovalsService oauthApprovalsService;

    /***
     * OauthApprovals分页条件搜索实现
     * @param oauthApprovals
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  OauthApprovals oauthApprovals, @PathVariable  int page, @PathVariable  int size){
        //调用OauthApprovalsService实现分页条件查询OauthApprovals
        PageInfo<OauthApprovals> pageInfo = oauthApprovalsService.findPage(oauthApprovals, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * OauthApprovals分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用OauthApprovalsService实现分页查询OauthApprovals
        PageInfo<OauthApprovals> pageInfo = oauthApprovalsService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param oauthApprovals
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<OauthApprovals>> findList(@RequestBody(required = false)  OauthApprovals oauthApprovals){
        //调用OauthApprovalsService实现条件查询OauthApprovals
        List<OauthApprovals> list = oauthApprovalsService.findList(oauthApprovals);
        return new Result<List<OauthApprovals>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用OauthApprovalsService实现根据主键删除
        oauthApprovalsService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改OauthApprovals数据
     * @param oauthApprovals
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  OauthApprovals oauthApprovals,@PathVariable String id){
        //设置主键值
        oauthApprovals.setUserId(id);
        //调用OauthApprovalsService实现修改OauthApprovals
        oauthApprovalsService.update(oauthApprovals);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增OauthApprovals数据
     * @param oauthApprovals
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   OauthApprovals oauthApprovals){
        //调用OauthApprovalsService实现添加OauthApprovals
        oauthApprovalsService.add(oauthApprovals);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询OauthApprovals数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OauthApprovals> findById(@PathVariable String id){
        //调用OauthApprovalsService实现根据主键查询OauthApprovals
        OauthApprovals oauthApprovals = oauthApprovalsService.findById(id);
        return new Result<OauthApprovals>(true,StatusCode.OK,"查询成功",oauthApprovals);
    }

    /***
     * 查询OauthApprovals全部数据
     * @return
     */
    @GetMapping
    public Result<List<OauthApprovals>> findAll(){
        //调用OauthApprovalsService实现查询所有OauthApprovals
        List<OauthApprovals> list = oauthApprovalsService.findAll();
        return new Result<List<OauthApprovals>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
